home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / batch / tsbat36.zip / D.BAT < prev    next >
DOS Batch File  |  1991-07-09  |  3KB  |  111 lines

  1. echo off
  2. echo.
  3. echo ┌───────────────────────────────────────────────────┐
  4. echo │ Directory with sort and generalized name matching │
  5. echo │ By Prof. Timo Salmi, ts@chyde.uwasa.fi, 9-Jul-91  │
  6. echo └───────────────────────────────────────────────────┘
  7. echo.
  8.  
  9. rem If no parameters are given to the batch, then display help
  10. if "%1"=="" goto _help
  11.  
  12. rem Check that a (ram)disk exists on r:
  13. if not exist r:\nul goto _err1
  14.  
  15. rem Make the searchstring uppercase
  16. set _tmp=%path%
  17. path %1
  18. set _upcase=%path%
  19. path %_tmp%
  20.  
  21. rem Make a temporary directory
  22. dir *.* > r:\d.tmp
  23.  
  24. rem Read the switches
  25. set _n=
  26. set _e=
  27. set _s=
  28. set _r=
  29. :_loop
  30. shift
  31. if "%1"=="" goto _sort_1
  32. if "%1"=="/n" set _n=yes
  33. if "%1"=="/N" set _n=yes
  34. if "%1"=="/e" set _e=yes
  35. if "%1"=="/E" set _e=yes
  36. if "%1"=="/s" set _s=yes
  37. if "%1"=="/S" set _s=yes
  38. if "%1"=="/r" set _r=/r
  39. if "%1"=="/R" set _r=/r
  40. goto _loop
  41.  
  42. rem The sorting routines
  43. :_sort_1
  44. if "%_n%"=="yes" goto _sort_n
  45. :_sort_2
  46. if "%_e%"=="yes" goto _sort_e
  47. :_sort_3
  48. if "%_s%"=="yes" goto _sort_s
  49. :_sort_4
  50. goto _display
  51.  
  52. :_sort_n
  53. sort %_r% < r:\d.tmp > r:\tmp$$$.$$$
  54. copy r:\tmp$$$.$$$ r:\d.tmp > nul
  55. del r:\tmp$$$.$$$
  56. goto _sort_2
  57.  
  58. :_sort_e
  59. sort %_r% /+10 < r:\d.tmp > r:\tmp$$$.$$$
  60. copy r:\tmp$$$.$$$ r:\d.tmp > nul
  61. del r:\tmp$$$.$$$
  62. goto _sort_3
  63.  
  64. :_sort_s
  65. sort %_r% /+14 < r:\d.tmp > r:\tmp$$$.$$$
  66. copy r:\tmp$$$.$$$ r:\d.tmp > nul
  67. del r:\tmp$$$.$$$
  68. goto _sort_4
  69.  
  70. rem Find the entries containing the searchstring
  71. :_display
  72. find "%_upcase%" r:\d.tmp | more
  73. goto _out
  74.  
  75. :_help
  76. echo D is a DIR command enhancement. It uses a generalized searchstring which is
  77. echo matched with the file name REGARDLESS of the location of the string within
  78. echo the file name. Wildcards (* and ?) should not be used. They are implicit.
  79. echo.
  80. echo Usage: D SearchString [/n] [/e] [/s] [/r]
  81. echo                         │    │    │    └─ Reverse the sort
  82. echo                         │    │    └─ Sort by size
  83. echo                         │    └─ Sort by extension
  84. echo                         └─ Sort by name
  85. echo.
  86. echo Examples: D bat /s /r  (all batch files sorted from biggest to smallest)
  87. echo           D - /n       (to see the entire sorted directory (- or . or /) )
  88. echo           D j          (all file names having a J in them, unsorted)
  89. echo           D /r         (error in logic, no sort key has been defined)
  90. echo.
  91. echo If you get an "Out of environment space" message, increase your environment
  92. echo space by using shell configuration in config.sys apply the following MsDos
  93. echo 3.30 example: shell=c:\bin\command.com /e:1024 /p
  94. goto _out
  95.  
  96. :_err1
  97. echo D.BAT assumes by default a (ram)disk in drive R. You do not have that
  98. echo drive is available, and you should substitute r:\d.bat throughout the
  99. echo batch as relevant for your own configuration. (Using a ramdisk is
  100. echo advisable, because potential read-only problems are avoided.)
  101.  
  102. :_out
  103. if exist r:\d.tmp del r:\d.tmp
  104. set _tmp=
  105. set _upcase=
  106. set _n=
  107. set _e=
  108. set _s=
  109. set _r=
  110. echo on
  111.